﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Xml;
using System.Reflection;
using System.IO;

namespace Pop3Client
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 3)
            {
                try
                {
                    Pop3Client client = new Pop3Client();
                    client.Info += new Pop3InfoHandler(client_Info);
                    client.Connect(args[0], args[1], args[2], true);
                    List<MailMessage> mails = client.getMails();
                    foreach (MailMessage mail in mails)
                    {
                        Console.WriteLine(mail.Body);
                        Console.ReadLine();
                        Console.Clear();

                    }
                    //Console.WriteLine(client.Receive(23));
                    client.Disconnect();
                }
                catch (Exception)
                {

                }
            }
            else
            {
                Console.WriteLine("Benutzung: \r\n\r\nAnwendung <Servername> <Benutzername> <Passwort>");
            }

            //schueler s = new schueler();
            //Console.WriteLine(s.GetType().AssemblyQualifiedName);
            //XmlDocument doc = new XmlDocument();
            //doc.LoadXml("<MailData><Name>Test</Name><Zusatz>Prof.</Zusatz></MailData>");
            ////Type t = typeof(schueler);
            //Assembly a = Assembly.GetExecutingAssembly();
            //Type t = Type.GetType("Pop3Client.schueler");
            ////Activator.CreateInstance(t);
            
            //foreach (XmlNode node in doc.SelectSingleNode("MailData").ChildNodes)
            //{
            //    PropertyInfo pi = t.GetProperty(node.Name);
            //    if (pi != null)
            //    {
            //        pi.SetValue(s, node.InnerText, null);
            //    }
            //}
            //Console.WriteLine(s.Zusatz + " " + s.Name);

            //string xml = File.ReadAllText("mail.xml");
            //MailParser parser = new MailParser();
            //List<object> objects = parser.ParseMail(xml);
            //foreach (object item in objects)
            //{
            //    Console.WriteLine(item.GetType().Name);
            //    foreach (PropertyInfo pi in item.GetType().GetProperties())
            //    {
            //        Console.WriteLine(pi.Name + " => " + pi.GetValue(item, null));
            //    }
            //    Console.WriteLine();
            //}
            
        }

        static void client_Info(string message)
        {
            Console.WriteLine(message);
        }
    }
}
